package com.kuangstudy.thread.demo1;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.net.URL;

/**
* ClassName: Demo2
* date: 2021/07/17 22:53:37
*@author zlk
*/public class Demo2 extends Thread{
    private String url;
    private String name;

    public Demo2() {
    }

    public Demo2(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        WebDownLoader webDownLoader = new WebDownLoader();
        try {
            webDownLoader.down(url,name);
            System.out.println("下载的文件名为"+name);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Demo2 thread1 = new Demo2("https://pics0.baidu.com/feed/810a19d8bc3eb135d6c55dc2bc7478dbfd1f4438.png?token=f9945350eb0262bdc5c918a4226a6494","1.jpg");
        Demo2 thread2 = new Demo2("https://pics5.baidu.com/feed/eac4b74543a98226c07c15d69fe869094b90eb70.png?token=f8f06d22232baa4549feb031457b29e6","2.jpg");
        Demo2 thread3 = new Demo2("https://pics1.baidu.com/feed/060828381f30e924c2c113a75b62be0e1c95f7b6.png?token=99d1ae2589b2215251746664a4a853c8","3.jpg");
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class WebDownLoader{
    public void down(String url,String name) throws Exception {
        FileUtils.copyURLToFile(new URL(url),new File(name));
    }
}
